package edu.ped.android.adapter;

import java.util.List;

import edu.ped.android.nfc.R;
import edu.ped.android.utils.Rule;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RulesAdapter extends BaseAdapter {

	private List<Rule> listeRules;
	private LayoutInflater inflater;
	public void setGesture(List<Rule> lg){
		this.listeRules = lg;
	}
	
	public RulesAdapter(Context context, List<Rule> listeRules) {
		this.listeRules = listeRules;
		this.inflater = LayoutInflater.from(context);
	}
	
	public int getCount() {
		return listeRules.size();
	}

	public Object getItem(int position) {
		return listeRules.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View view, ViewGroup viewGroup) {
		final ViewHolder holder;

		if (view == null) {
			holder = new ViewHolder();
			view = inflater.inflate(R.layout.rule_item, null);
			holder.tvRulesName = (TextView) view.findViewById(R.id.ruleNameItemTV);
			holder.tvRulesDesc = (TextView) view.findViewById(R.id.ruleDescItemTV);
			view.setTag(position);
			
		} else {
			holder = (ViewHolder) view.getTag();
		}

		Log.i("PED", "contenu list ");//+listeRules);
		if(listeRules != null){
			Log.i("PED", "Taile list Adapter"+listeRules.size()+"Position:"+position);
			holder.tvRulesName.setText(listeRules.get(position).getName());
			holder.tvRulesDesc.setText(listeRules.get(position).getDescription());
		}
		
		return view;

	}
	
	private class ViewHolder {
		public TextView tvRulesName;
		public TextView tvRulesDesc;
	}
	

}
